<?php
/**
 * Created by PhpStorm.
 * User: qingyun
 * Date: 17/4/26
 * Time: 下午7:35
 */
namespace Admin\Controller;
use Common\Controller\AdminBaseController;

class MenuController extends AdminBaseController{
    public function index(){
        $menu = M('Menu');
        $list = $menu -> order('type,px') -> select();

        $list = get_tree($list, 0, 0, '----&nbsp;');
        $this -> assign('list', $list);
        $this -> display();
    }
    public function pageList(){

    }

    public function save(){
        if(IS_AJAX && IS_POST){
            $menu = D('Menu');
            $this -> ajaxReturn($menu -> addMenu(I('post.')));
        }
    }

    public function statusChange(){
        if(IS_AJAX && IS_POST){
            $menu = D('Menu');
            $this -> ajaxReturn($menu -> changeStatus(I('post.id')));
        }
    }

    public function del(){
        if(IS_AJAX && IS_POST){
            $menu = D('Menu');
            $this -> ajaxReturn($menu -> del(I('post.id')));
        }
    }

    //  修改时 获取数据
    public function getMenu(){
        if(IS_POST && IS_AJAX){
            $result = D('menu')->menuList(I('post.id/d',0),'id,pid,title,link,px,status');
            $this->ajaxReturn($result);
        }
    }
}